package com.lengxf.aPlugins;

import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.EasyExcel;
import com.lengxf.aPlugins.bizType.BizEnums;
import com.lengxf.aPlugins.model.DaLianAreaEnum;
import com.lengxf.aPlugins.model.ReadExcelModel;
import com.lengxf.aPlugins.model.WriteExcelModel;
import com.lengxf.aPlugins.service.PointGenerateService;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class Application {

    private final static PointGenerateService pointGenerateService = new PointGenerateService();

    /**
     * 通过枚举生成
     */
    public static void main1(String[] args) {
        long start = System.currentTimeMillis();
        System.out.println("开始生成...");
        DaLianAreaEnum[] values = DaLianAreaEnum.values();
        for (DaLianAreaEnum value : values) {
            new PointGenerateService().generate(value);
        }
        System.out.println("累计耗时：" + (System.currentTimeMillis() - start));
        System.out.println("生成完成...");
    }

    /**
     * 通过读取excel生成
     */
    public static void main(String[] args) {
        String excelPath = "./a-plugins/src/main/java/com/lengxf/aPlugins/excelsource/焊装车间点位配置.xlsx";
        List<ReadExcelModel> readExcelModels = new ArrayList<>();
        for (BizEnums bizEnums : BizEnums.values()) {
            List<ReadExcelModel> list = EasyExcel.read(excelPath)
                    .head(ReadExcelModel.class)
                    .sheet(bizEnums.getBizName())
                    .doReadSync();
            for (ReadExcelModel readExcelModel : list) {
                readExcelModel.setBizEnums(bizEnums);
                readExcelModels.add(readExcelModel);
            }
        }
        readExcelModels.stream()
                .filter(e -> StrUtil.isNotBlank(e.getAreaEn()))
                .collect(Collectors.groupingBy(ReadExcelModel::getAreaEn))
                .forEach(Application::doGenerate);
    }

    private static void doGenerate(String key, List<ReadExcelModel> value) {
        WriteExcelModel writeExcelModel = new WriteExcelModel();
        writeExcelModel.setAreaEn(key);
        writeExcelModel.setArea(value.get(0).getAreaName());
        writeExcelModel.buildInfoList(value);
        pointGenerateService.generate(writeExcelModel);
    }

}
